package com.gitee.huanminabc.fastboot.web.validation;

import com.gitee.huanminabc.fastboot.exception.ValidationException;
import com.gitee.huanminabc.fastboot.web.annotation.validation.Min;

import java.lang.annotation.Annotation;

/**
 * @description:
 * @author: huanmin
 * @create: 2025-04-02 15:11
 **/
public class MinValidationVerify implements ValidationVerify {
    @Override
    public Class<?> getAnnotation() {
        return Min.class;
    }

    @Override
    public void verify(Object value, Annotation annotation,String gprmc) {
        if (value instanceof Number) {
            Min min = (Min) annotation;
            Number number = (Number) value;
            if (number.doubleValue() < min.value()) {
                String message= min.message();
                //替换{value1}和{value2}
                message = message.replace("{value1}", String.valueOf(number.doubleValue())).replace("{value2}", String.valueOf(min.value()));
                throw new ValidationException(this.gprmcMerge(gprmc, message));
            }
        }
    }
}
